package com.slt.android.amigodemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.io.File;

import me.ele.amigo.Amigo;

/**
 * 说明:
 * 可以修改除了contentprovider以外的所有东西
 * 比如增加资源，activity，service等等
 * 使用方法：
 * 1.导入依赖。
 * 2.Amigo.work(this, apkFile);
 * 3.amigo_old.apk中删除TestActivity、activity_test.xml mainifest中test activity
 * >onclick方法改变
 * 注意事项：
 * 1.需要有 myapplication
 * 2.loadPatch方法在新 旧 apk中都必须这样写
 */
public class MainActivity extends Activity implements View.OnClickListener {

    Button btn;
    File apkFile;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        loadPatch();
    }

    private void initView() {
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(this);
    }

    private void loadPatch() {
        apkFile = new File(Environment.getExternalStorageDirectory(), "amigo_new.apk");
        if (apkFile.exists()) {
            Amigo.work(this, apkFile);
        } else {

        }
    }

    @Override
    public void onClick(View v) {
        Intent i = new Intent(MainActivity.this , TestActivity.class);
        startActivity(i);
        Toast.makeText(this , "修复之后" , Toast.LENGTH_SHORT).show();
    }

//    @Override
//    public void onClick(View v) {
//        Toast.makeText(this , "修复之前" , Toast.LENGTH_SHORT).show();
//    }
}
